#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年4月22日

@author: chenyongbing
'''
import sys,os,datetime
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]
sys.path.append(os.path.join(current_dir,'../../'))
import logging


# logfile = os.path.join(current_dir,'../log/zm_data_check.log')
#  
#  
# try:
#     os.remove(logfile)
# except:pass
# logging.basicConfig(filename=logfile,level=logging.DEBUG,format='%(message)s')



from base.zhimind_datas import ZhimindDatas
from base.time_method import myTimeMethod
#from base.zhimind_hive_datas import myZhimindHiveDatas
# level = logging.DEBUG
# console = logging.StreamHandler()
# console.setLevel(level)
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# console.setFormatter(formatter)
# logging.getLogger('').addHandler(console)






class ZhimindDataCheck(object):
    '''
    classdocs
    '''


    def __init__(self,st=None,et=None):
        '''
        Constructor
        '''
        #self.myZhimindDatas = ZhimindDatas(st=st,et=et)
        #self.day_query = self.myZhimindDatas.__day_query__(st, et)
        if st==None or et==None:
            self.day = datetime.date.today().strftime('%Y-%m-%d')
            self.st = self.day
            self.et = self.day
        else:
            self.day = st
            self.st = st
            self.et = et
     
     
     
    def check_customer_flow_with_hive_data(self,tab='mac_customer_stats',groupType=4):
        u'''验证 %s 入店量 入店人数'''%tab
        customer_flow = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group( distinct=False)
        customer_mac_count = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group( distinct=True)
     
        check_customer_flow = myZhimindHiveDatas.get_flow_by_group_and_type(day=self.day, role=3, distinct=False)
        check_customer_mac_count = myZhimindHiveDatas.get_flow_by_group_and_type(day=self.day, role=3, distinct=True)
        
        if self.__check_two_dict_group_key__(customer_flow , check_customer_flow):
            logging.info(u'Table:%s 顾客人次ByGroup(%s) .... OK'%(tab,sum(customer_flow.values())))
        else:
            logging.error('Table:%s 顾客人次ByGroup(%s:%s) .... Faild'%(tab,sum(customer_flow.values()),sum(check_customer_flow.values())))
        
        if self.__check_two_dict_group_key__(customer_mac_count , check_customer_mac_count):
            logging.info(u'Table:%s 顾客人次ByGroup(%s) .... OK'%(tab,sum(customer_mac_count.values())))
        else:
            logging.error('Table:%s 顾客人次ByGroup(%s:%s) .... Faild'%(tab,sum(customer_mac_count.values()),sum(check_customer_mac_count.values())))
        
        
     
     
    def check_first_day_by_history(self,tab='mac_customer_stats',groupType=4):
        u'''验证first_day'''
        tab = self.myZhimindDatas.__get_mac_customer_stats_tab__(groupType)
        day_date = datetime.date(int(self.day[:4]),int(self.day[5:7]),int(self.day[8:10]))
        last_day_st = (day_date - datetime.timedelta(180)).strftime('%Y-%m-%d')
        last_day_et = (day_date - datetime.timedelta(1)).strftime('%Y-%m-%d')
        
        query = 'select count(*) from %s where (dgroup,mac) in (select dgroup,mac from %s where day=first_day and %s) and day between "%s" and "%s"'%(tab,tab,self.day_query,last_day_st,last_day_et)
        logging.debug( query)
        count = self.myZhimindDatas.myZhimind.SelectCount(query)
        
        if count==0:
            logging.info(u'Table:%s first_day  验证 ... OK'%(tab))
        else:
            logging.error(u'Table:%s first_day 验证 ... Faild'%(tab))
            sys.exit()
        
    def check_delta_day_by_first_day(self,tab='mac_customer_stats',groupType=4):
        u'''验证delta_day'''
        tab = self.myZhimindDatas.__get_mac_customer_stats_tab__(groupType)
        query = 'select count(*) from %s where %s and ((first_day=day and delta_day!=0) or (first_day!=day and delta_day=0))'%(tab,self.day_query)
        logging.debug(query)
        count = self.myZhimindDatas.myZhimind.SelectCount(query)
        if count==0:
            logging.info(u'Table:%s  delta_day 验证 ... OK'%(tab))
        else:
            logging.error(u'Table:%s delta_day 验证 ... Faild'%(tab))
            sys.exit()
            

    
    def check_region_mac_customer_stats(self,tab='mac_customer_stats',groupType=2,group=None,targetList=[]):
        u'''
            验证 city_mac_customer_stats \ prov_mac_customer_stats \ comp_mac_customer_stats
            
            字段：dur_type_*_cnt deep_visit_sum_dur deep_visit_cust_visit_cnt jump_out_cust_visit_cnt  visit_freq sum_dur
        '''
        
        
        if targetList==None:
            targetList = ['cust_cnt','cust_visit_cnt','sum_dur','deep_visit_sum_dur',
                              'deep_visit_cust_visit_cnt','jump_out_cust_visit_cnt',
                              'dur_type_1_cnt','dur_type_2_cnt',
                              'dur_type_3_cnt','dur_type_4_cnt'
                              ]
        
    
        tab = self.myZhimindDatas.__get_mac_customer_stats_tab__(groupType)
        if groupType == 2:
            group_field_name = 'city_group'
        elif groupType == 1:
            group_field_name = 'prov_group'
        elif groupType == 0:
            group_field_name = 'comp_group'
        else:
            group_field_name = 'dgroup'
            logging.warning('Table:%s 不需要验证.'%tab)
            return
        same_target =  self.myZhimindDatas.get_same_target_from_mac_customer_stats(group=group,groupType=4,targetList=targetList,group_field_name=group_field_name)
        same_check_target =  self.myZhimindDatas.get_same_target_from_mac_customer_stats(tab=tab,group=group,groupType=groupType,targetList=targetList)
        if same_target == same_check_target:
            logging.info(u'Table:%s 验证字段(%s) .... OK'%(tab,len(same_target)))
        else:
            logging.error('Table:%s 验证字段(%s:%s) .... Faild'%(tab,len(same_target),len(same_check_target)))
        
    


    
    
    def check_customer_cnt_in_customer_type_stats(self,tab='customer_type_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 顾客数'''%tab
        tab = timeType+'_'+tab
        new_customer_dist_cnt = self.myZhimindDatas.get_customer_dist_cnt_from_mac_customer_stats(role=3, group=group,groupType=groupType)
        all_customer_dist_cnt = self.myZhimindDatas.get_customer_dist_cnt_from_mac_customer_stats(role=0, group=group,groupType=groupType)
        old_customer_dist_cnt = all_customer_dist_cnt - new_customer_dist_cnt
        all_customer_dist_cnt_check = self.myZhimindDatas.get_customer_dist_cnt_from_customer_type_stats( role=0, group=group,groupType=groupType,timeType=timeType)
        new_customer_dist_cnt_check = self.myZhimindDatas.get_customer_dist_cnt_from_customer_type_stats( role=3, group=group,groupType=groupType,timeType=timeType)
        old_customer_dist_cnt_check = self.myZhimindDatas.get_customer_dist_cnt_from_customer_type_stats( role=10, group=group,groupType=groupType,timeType=timeType)
        if all_customer_dist_cnt == all_customer_dist_cnt_check:
            logging.info(u'Table:%s 验证顾客数(%s) .... OK'%(tab,all_customer_dist_cnt))
        else:
            logging.error('Table:%s 验证顾客数(%s:%s) .... Faild'%(tab,all_customer_dist_cnt,all_customer_dist_cnt_check))
        if new_customer_dist_cnt == new_customer_dist_cnt_check:
            logging.info(u'Table:%s 验证新顾客数(%s) .... OK'%(tab,new_customer_dist_cnt))
        else:
            logging.error(u'Table:%s 验证新顾客数(%s:%s) .... Faild'%(tab,new_customer_dist_cnt,new_customer_dist_cnt_check))
        
        if old_customer_dist_cnt == old_customer_dist_cnt_check:
            logging.info(u'Table:%s 验证老顾客数(%s) .... OK'%(tab,old_customer_dist_cnt))
        else:
            logging.error(u'Table:%s 验证老顾客数(%s:%s) .... Faild'%(tab,old_customer_dist_cnt,old_customer_dist_cnt_check))
    
    
    def check_customer_cnt_in_customer_type_stats_by_group(self,tab='customer_type_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 顾客数'''%tab
        tab = timeType+'_'+tab
        new_customer_dist_cnt = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(role=3, group=group,groupType=groupType)
        all_customer_dist_cnt = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(role=0, group=group,groupType=groupType)
        old_customer_dist_cnt = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(role=10, group=group,groupType=groupType)
        all_customer_dist_cnt_check = self.myZhimindDatas.get_customer_dist_cnt_from_customer_type_stats_by_group( role=0, group=group,groupType=groupType,timeType=timeType)
        new_customer_dist_cnt_check = self.myZhimindDatas.get_customer_dist_cnt_from_customer_type_stats_by_group( role=3, group=group,groupType=groupType,timeType=timeType)
        old_customer_dist_cnt_check = self.myZhimindDatas.get_customer_dist_cnt_from_customer_type_stats_by_group( role=10, group=group,groupType=groupType,timeType=timeType)
       
        
        if self.__check_two_dict_group_key__(all_customer_dist_cnt, all_customer_dist_cnt_check):
            logging.info(u'Table:%s 验证顾客数ByGroup(%s) .... OK'%(tab,sum(all_customer_dist_cnt.values())))
        else:
            logging.error('Table:%s 验证顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(all_customer_dist_cnt.values()),sum(all_customer_dist_cnt_check.values())))
        if self.__check_two_dict_group_key__(new_customer_dist_cnt, new_customer_dist_cnt_check):
            logging.info(u'Table:%s 验证新顾客数ByGroup(%s) .... OK'%(tab,sum(new_customer_dist_cnt.values())))
        else:
            logging.error(u'Table:%s 验证新顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(new_customer_dist_cnt.values()),sum(new_customer_dist_cnt_check.values())))
        
        if self.__check_two_dict_group_key__(old_customer_dist_cnt, old_customer_dist_cnt_check):
            logging.info(u'Table:%s 验证老顾客数ByGroup(%s) .... OK'%(tab,sum(old_customer_dist_cnt.values())))
        else:
            logging.error(u'Table:%s 验证老顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(old_customer_dist_cnt.values()),sum(old_customer_dist_cnt_check.values())))
    
    
    
    def check_customer_cnt_in_rank_stats(self,tab='rank_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 顾客数'''%tab
        tab = timeType+'_'+tab
        new_customer_dist_cnt = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(role=3, group=group,groupType=groupType)
        all_customer_dist_cnt = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(role=0, group=group,groupType=groupType)
        old_customer_dist_cnt = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(role=10, group=group,groupType=groupType)
        
        new_customer_dist_cnt_check,old_customer_dist_cnt_check = self.myZhimindDatas.get_customer_dist_cnt_from_rank_stats_by_group(timeType=timeType,group= group,groupType=groupType)
        if self.__check_two_dict_group_key__(new_customer_dist_cnt , new_customer_dist_cnt_check):
            logging.info(u'Table:%s 验证新顾客数 With Rank Tab ByGroup(%s) .... OK'%(tab,sum(new_customer_dist_cnt.values())))
        else:
            logging.error(u'Table:%s 验证新顾客数 With Rank Tab ByGroup(%s:%s) .... Faild'%(tab,sum(new_customer_dist_cnt.values()),sum(new_customer_dist_cnt_check.values())))
        
        if self.__check_two_dict_group_key__(old_customer_dist_cnt , old_customer_dist_cnt_check):
            logging.info(u'Table:%s 验证老顾客数 With Rank Tab ByGroup(%s) .... OK'%(tab,sum(old_customer_dist_cnt.values())))
        else:
            logging.error(u'Table:%s 验证老顾客数 With Rank Tab ByGroup(%s:%s) .... Faild'%(tab,sum(old_customer_dist_cnt.values()),sum(old_customer_dist_cnt_check.values())))
    
    
    
        
    
    
    
    def check_deep_jump_customer_cnt_in_customer_type_stats(self,tab='customer_type_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 深访跳出顾客'''%tab
        tab = timeType+'_'+tab
        
        all_deep_visit_cust_visit_cnt , all_jump_out_cust_visit_cnt = self.myZhimindDatas.get_deep_jump_customer_cnt_from_mac_customer_stats_by_group(  group=group,groupType=groupType, role=0)
        
        new_deep_visit_cust_visit_cnt , new_jump_out_cust_visit_cnt = self.myZhimindDatas.get_deep_jump_customer_cnt_from_mac_customer_stats_by_group(  group=group,groupType=groupType, role=3)
        old_deep_visit_cust_visit_cnt , old_jump_out_cust_visit_cnt = self.myZhimindDatas.get_deep_jump_customer_cnt_from_mac_customer_stats_by_group(  group=group,groupType=groupType, role=10)
        
        
        all_deep_visit_cust_visit_cnt_check , all_jump_out_cust_visit_cnt_check = self.myZhimindDatas.get_deep_jump_customer_cnt_from_customer_type_stats_by_group( timeType=timeType, group=group,groupType=groupType, role=0)
        
        new_deep_visit_cust_visit_cnt_check , new_jump_out_cust_visit_cnt_check = self.myZhimindDatas.get_deep_jump_customer_cnt_from_customer_type_stats_by_group( timeType=timeType, group=group,groupType=groupType, role=3)
        old_deep_visit_cust_visit_cnt_check , old_jump_out_cust_visit_cnt_check = self.myZhimindDatas.get_deep_jump_customer_cnt_from_customer_type_stats_by_group( timeType=timeType, group=group,groupType=groupType, role=10)
        
        
        if self.__check_two_dict_group_key__(all_deep_visit_cust_visit_cnt ,all_deep_visit_cust_visit_cnt_check):
            logging.info(u'Table:%s 验证深访顾客数ByGroup(%s) .... OK'%(tab,sum(all_deep_visit_cust_visit_cnt.values())))
        else:
            logging.error('Table:%s 验证深访顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(all_deep_visit_cust_visit_cnt.values()),sum(all_deep_visit_cust_visit_cnt_check.values())))
        

        if self.__check_two_dict_group_key__(all_jump_out_cust_visit_cnt , all_jump_out_cust_visit_cnt_check):
            logging.info(u'Table:%s 验证跳出顾客数ByGroup(%s) .... OK'%(tab,sum(all_jump_out_cust_visit_cnt.values())))
        else:
            logging.error('Table:%s 验证跳出顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(all_jump_out_cust_visit_cnt.values()),sum(all_jump_out_cust_visit_cnt_check.values())))
        
        #新顾客
        if self.__check_two_dict_group_key__(new_deep_visit_cust_visit_cnt, new_deep_visit_cust_visit_cnt_check):
            logging.info(u'Table:%s 验证深访新顾客数ByGroup(%s) .... OK'%(tab,sum(new_deep_visit_cust_visit_cnt.values())))
        else:
            logging.error('Table:%s 验证深访新顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(new_deep_visit_cust_visit_cnt.values()),sum(new_deep_visit_cust_visit_cnt_check.values())))
        
        if self.__check_two_dict_group_key__(new_jump_out_cust_visit_cnt , new_jump_out_cust_visit_cnt_check):
            logging.info(u'Table:%s 验证跳出新顾客数ByGroup(%s) .... OK'%(tab,sum(new_jump_out_cust_visit_cnt.values())))
        else:
            logging.error('Table:%s 验证跳出新顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(new_jump_out_cust_visit_cnt.values()),sum(new_jump_out_cust_visit_cnt_check.values())))
        
        #老顾客
        if self.__check_two_dict_group_key__(old_deep_visit_cust_visit_cnt , old_deep_visit_cust_visit_cnt_check):
            logging.info(u'Table:%s 验证深访老顾客数ByGroup(%s) .... OK'%(tab,sum(old_deep_visit_cust_visit_cnt.values())))
        else:
            logging.error('Table:%s 验证深访老顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(old_deep_visit_cust_visit_cnt.values()),sum(old_deep_visit_cust_visit_cnt_check.values())))
        
        if self.__check_two_dict_group_key__(old_jump_out_cust_visit_cnt , old_jump_out_cust_visit_cnt_check):
            logging.info(u'Table:%s 验证跳出老顾客数ByGroup(%s) .... OK'%(tab,sum(old_jump_out_cust_visit_cnt.values())))
        else:
            logging.error('Table:%s 验证跳出老顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(old_jump_out_cust_visit_cnt.values()),sum(old_jump_out_cust_visit_cnt_check.values())))
    
    
    
    
    
    def check_active_customer_equal_old_customer(self,tab='customer_type_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 活跃度顾客==老顾客'''%tab
        tab = timeType+'_'+tab
        
        old_customer_cnt = self.myZhimindDatas.get_customer_dist_cnt_from_customer_type_stats_by_group(timeType=timeType, role=10, group=group,groupType=groupType)
        sum_active_customer_cnt = self.myZhimindDatas.get_active_customer_cnt_from_customer_type_stats_by_group(timeType=timeType, group=group,groupType=groupType)
        if self.__check_two_dict_group_key__(old_customer_cnt, sum_active_customer_cnt):
            logging.info(u'Table:%s 验证老顾客数:活跃度顾客数ByGroup(%s) .... OK'%(tab,sum(old_customer_cnt.values())))
        else:
            logging.error('Table:%s 验证老顾客数:活跃度顾客数ByGroup(%s:%s) .... Faild'%(tab,sum(old_customer_cnt.values()),sum(sum_active_customer_cnt.values())))
    
    
    def check_avg_visit_cycle_in_customer_type_stats(self,tab='customer_type_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 平均到访周期 by '''%tab
        u'''平均到访周期 只计算了 全部顾客的 ；实际还是计算的老顾客；在%s 中 role=0'''%tab
        
        
        tab = timeType+'_'+tab
        
        avg_visit_cycle = self.myZhimindDatas.get_avg_visit_cycle_from_mac_customer_stats(group=group,groupType=groupType)
        avg_visit_cycle_check = self.myZhimindDatas.get_avg_visit_cycle_from_customer_type_stats(timeType= timeType,group= group,groupType=groupType)
        if self.__check_two_dict_group_key__(avg_visit_cycle, avg_visit_cycle_check):
             logging.info(u'Table:%s 验证老顾客平均到访周期ByGroup .... OK'%(tab))
        else:
            logging.error('Table:%s 验证老顾客平均到访周期ByGroup .... Faild'%(tab))
    
#     
#     def __check_two_dict_group_key__(self,dict1,dict2):
#         for group in dict2.keys():
#             if group not in dict1.keys():
#                 del dict2[group]
#         if dict1==dict2:
#             return True
#         else:
#             return False
    
  
     
    def __check_two_dict_group_key__(self,dict1,dict2,target=None):
        
        for group in dict2.keys():
            if group  in dict1.keys():
                if target!=None:
                    if dict2[group][target] != dict1[group][target]:
                        print group,target,dict2[group][target] , dict1[group][target]
                        return False
                else:
                    if dict2[group] != dict1[group]:
                        return False
            else:
                pass
                #logging.debug('%s not in check msg.'%group)
        return True
    
    
    def __get_sum_value__(self,dict1,target=None):
        if target==None:
            return sum(dict1.values())
        sum_value = 0
        for group in dict1.keys():
            sum_value+=dict1[group][target]
        return sum_value
    
    def check_same_target_by_group_in_customer_type_stats(self,tab='customer_type_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 指标 ： 顾客数(cust_cnt)、到访次数(cust_visit_cnt)、
            停留时长总和(sum_dur)、平均停留时长(avg_dur)、
            深访停留时长总和(deep_visit_sum_dur)、深访次数(deep_visit_cust_visit_cnt)、
            跳出停留时长总和(jump_out_cust_visit_cnt)'''%tab
        tab = timeType+'_'+tab
        targetList =  ['cust_cnt', 'cust_visit_cnt', 'sum_dur', 'avg_dur', 'deep_visit_sum_dur', 
     'deep_visit_cust_visit_cnt', 'jump_out_cust_visit_cnt']
        
        for role in [0,3,10]:
            same_target =  self.myZhimindDatas.get_same_target_from_mac_customer_stats(group=group,role=role,groupType=groupType,targetList=targetList)
            same_target_check = self.myZhimindDatas.get_same_target_from_customer_type_stats(group=group,groupType=groupType,role=role, timeType=timeType,targetList=targetList)
            for target in targetList:
#                 same_target_sum = self.__get_sum_value__(same_target, target)
#                 same_target_check_sum = self.__get_sum_value__(same_target_check, target)
#                 
                if self.__check_two_dict_group_key__(same_target, same_target_check,target):
                     logging.info(u'Table:%s role:%s target:%s 验证指标ByGroup(%s:%s) .... OK'%(tab,role,target,len(same_target),len(same_target_check)))
                else:
                    logging.error('Table:%s role:%s target:%s 验证指标ByGroup(%s:%s) .... Faild'%(tab,role,target,len(same_target),len(same_target_check)))
                
    def check_walkby_cnt_in_rank_stats(self,tab='rank_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 路人人次'''
        tab = timeType+'_'+tab
        if timeType == 'day':
            walkby_cnt = self.myZhimindDatas.get_walkby_cnt_from_mac_walkby_stats_by_group( group=group,distinct=False,groupType=groupType)
        else:
            walkby_cnt = self.myZhimindDatas.get_walkby_cnt_from_rank_stats_by_group(timeType= 'day', group=group,groupType=groupType)
        
        walkby_cnt_check = self.myZhimindDatas.get_walkby_cnt_from_rank_stats_by_group(timeType= timeType, group=group,groupType=groupType)
        if self.__check_two_dict_group_key__(walkby_cnt , walkby_cnt_check):
             logging.info(u'Table:%s 路人人次验证(%s) .... OK'%(tab,sum(walkby_cnt.values())))
        else:
            logging.error('Table:%s 路人人次验证(%s:%s) .... Faild'%(tab,sum(walkby_cnt.values()),sum(walkby_cnt_check.values())))
            
    
    def check_distinct_visit_cnt_in_rank_stats(self,tab='rank_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 到访人数 剔除了员工'''
        tab = timeType+'_'+tab
        distinct_visit_cnt = self.myZhimindDatas.get_visit_cnt_by_group(group=group, groupType=groupType)
        distinct_visit_cnt_check = self.myZhimindDatas.get_dist_visit_cnt_from_rank_stats_by_group(timeType= timeType, group=group,groupType=groupType)
        if self.__check_two_dict_group_key__(distinct_visit_cnt, distinct_visit_cnt_check):
             logging.info(u'Table:%s  验证客流人数ByGroup(%s) .... OK'%(tab,sum(distinct_visit_cnt.values())))
        else:
            logging.error('Table:%s  验证客流人数ByGroup(%s:%s) .... Faild'%(tab,sum(distinct_visit_cnt.values()),sum(distinct_visit_cnt_check.values())))
        #print distinct_visit_cnt,distinct_visit_cnt_check
            
    
    def check_same_target_in_rank_stats(self,tab='rank_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 指标
                ent_cust_rate 入店率 --自检
                ent_cust_cnt 入店量
                visit_cnt  客流量
                old_cust_rate 老顾客比例 --自检
                new_cust 新顾客人数
                new_visit_rate 新顾客入店率  --暂缓
                old_cust 老顾客人数
                old_visit_rate 重复客流入店率 --暂缓
                ent_cust_dur 平均驻店时长
                old_cust_visit_freq 老顾客每日到访总次数 --废弃
                new_visit 新客流 --暂缓
                
        
        '''
        tab = timeType+'_'+tab
        
        
        targetList = ['ent_cust_cnt','new_cust','old_cust','ent_cust_dur','visit_cnt','cust_avl_days']
        
        if 'ent_cust_cnt' in targetList:
            ent_cust_cnt = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(  distinct=False, group=group, groupType=groupType, st=self.st, et=self.et)
            check_ent_cust_cnt = self.myZhimindDatas.get_one_target_from_rank_stats_by_group( timeType=timeType, group=group, groupType=groupType, st=self.st, et=self.et, target='ent_cust_cnt')
            if self.__check_two_dict_group_key__(ent_cust_cnt, check_ent_cust_cnt):
                logging.info(u'Table:%s  验证入店人次ByGroup(%s) .... OK'%(tab,sum(ent_cust_cnt.values())))
            else:
                logging.error('Table:%s  验证入店人次ByGroup(%s:%s) .... Faild'%(tab,sum(ent_cust_cnt.values()),sum(check_ent_cust_cnt.values())))
                
        if 'visit_cnt' in targetList:
            if timeType == 'day' or timeType == 'week':
                visit_cnt = self.myZhimindDatas.get_visit_cnt_by_group(group=group, st=self.st, et=self.et, groupType=groupType, distinct=False)
            else:
                visit_cnt = self.myZhimindDatas.get_one_target_from_rank_stats_by_group( timeType='day', group=group, groupType=groupType, st=self.st, et=self.et, target='visit_cnt')
            check_visit_cnt = self.myZhimindDatas.get_one_target_from_rank_stats_by_group( timeType=timeType, group=group, groupType=groupType, st=self.st, et=self.et, target='visit_cnt')
            if self.__check_two_dict_group_key__(visit_cnt, check_visit_cnt):
                logging.info(u'Table:%s  验证客流人次ByGroup(%s) .... OK'%(tab,sum(visit_cnt.values())))
            else:
                logging.error('Table:%s  验证客流人次ByGroup(%s:%s) .... Faild'%(tab,sum(visit_cnt.values()),sum(check_visit_cnt.values())))
                 
        if 'new_cust' in targetList:
            new_cust = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(  role=3, group=group, groupType=groupType, st=self.st, et=self.et)
            check_new_cust = self.myZhimindDatas.get_one_target_from_rank_stats_by_group( timeType=timeType, group=group, groupType=groupType, st=self.st, et=self.et, target='new_cust')
            if self.__check_two_dict_group_key__(new_cust, check_new_cust):
                logging.info(u'Table:%s  验证新顾客人数ByGroup(%s) .... OK'%(tab,sum(new_cust.values())))
            else:
                logging.error('Table:%s  验证新顾客人数ByGroup(%s:%s) .... Faild'%(tab,sum(new_cust.values()),sum(check_new_cust.values())))
                
        if 'old_cust' in targetList:
            old_cust = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(  role=10, group=group, groupType=groupType, st=self.st, et=self.et)
            check_old_cust = self.myZhimindDatas.get_one_target_from_rank_stats_by_group( timeType=timeType, group=group, groupType=groupType, st=self.st, et=self.et, target='old_cust')
            if self.__check_two_dict_group_key__(old_cust, check_old_cust):
                logging.info(u'Table:%s  验证老顾客人数ByGroup(%s) .... OK'%(tab,sum(old_cust.values())))
            else:
                logging.error('Table:%s  验证老顾客人数ByGroup(%s:%s) .... Faild'%(tab,sum(old_cust.values()),sum(check_old_cust.values())))
                
        if 'ent_cust_dur' in targetList:
            avg_ent_cust_dur = self.myZhimindDatas.get_customer_dur_from_mac_customer_stats_by_group( group=group, groupType=groupType, st=self.st, et=self.et,atype='avg')
            check_avg_ent_cust_dur = self.myZhimindDatas.get_one_target_from_rank_stats_by_group( timeType=timeType, group=group, groupType=groupType, st=self.st, et=self.et, target='ent_cust_dur')
            if self.__check_two_dict_group_key__(avg_ent_cust_dur, check_avg_ent_cust_dur):
                logging.info(u'Table:%s  验证平均停留时长ByGroup(%s) .... OK'%(tab,sum(avg_ent_cust_dur.values())))
            else:
                logging.error('Table:%s  验证平均停留时长ByGroup(%s:%s) .... Faild'%(tab,sum(avg_ent_cust_dur.values()),sum(check_avg_ent_cust_dur.values())))
                
        
        if 'cust_avl_days' in targetList and timeType!='day':
            cust_avl_days  = self.myZhimindDatas.get_customer_visit_days_by_group( group=group, groupType=groupType, st=self.st, et=self.et)
            check_cust_avl_days = self.myZhimindDatas.get_one_target_from_rank_stats_by_group( timeType=timeType, group=group, groupType=groupType, st=self.st, et=self.et, target='cust_avl_days')
        
            if self.__check_two_dict_group_key__(avg_ent_cust_dur, check_avg_ent_cust_dur):
                logging.info(u'Table:%s  营业时间天数ByGroup(%s) .... OK'%(tab,sum(avg_ent_cust_dur.values())))
            else:
                logging.error('Table:%s  营业时间天数ByGroup(%s:%s) .... Faild'%(tab,sum(avg_ent_cust_dur.values()),sum(check_avg_ent_cust_dur.values())))
                
    


            

    
    
#         if timeType=='day':
#             old_cust_visit_freq = self.myZhimindDatas.get_customer_total_visit_freq_from_mac_customer_stats_by_group(group=group, groupType=groupType, day=self.day, role=10)
#             check_old_cust_visit_freq = self.myZhimindDatas.get_one_target_from_rank_stats_by_group( timeType=timeType, group=group, groupType=groupType, st=self.st, et=self.et, target='old_cust_visit_freq')
#             if self.__check_two_dict_group_key__(old_cust_visit_freq, check_old_cust_visit_freq):
#                 logging.info(u'Table:%s  验证老顾客到访次数ByGroup(%s) .... OK'%(tab,sum(old_cust_visit_freq.values())))
#             else:
#                 logging.error('Table:%s  验证老顾客到访次数ByGroup(%s:%s) .... Faild'%(tab,sum(old_cust_visit_freq.values()),sum(check_old_cust_visit_freq.values())))
#                 
#             
        
    
    
    def check_self_target_in_rank_stats(self,tab='rank_stats',timeType='day',group=None,groupType=4):
        u'''验证 %s 指标
                ent_cust_rate 入店率 --自检 = ent_cust_cnt/visit_cnt
                ent_cust_cnt 入店量
                visit_cnt  客流量
                old_cust_rate 老顾客比例 --自检 = new_cust/(new_cust+old_cust)
                new_cust 新顾客人数
                old_cust 老顾客人数

                
        
        '''
        tab = timeType+'_'+tab
        targetList = ['ent_cust_rate','ent_cust_cnt','visit_cnt','old_cust_rate','new_cust','old_cust']
        
        query = 'select any_group,ent_cust_rate,round(ent_cust_cnt*1.0/visit_cnt*1.0,3),old_cust_rate,round(old_cust/(old_cust+new_cust),3) from %s\
                 where day="%s" and group_type="%s" '%(tab,self.day,groupType)
                 
        logging.debug(query)
        rets = self.myZhimindDatas.myZhimind.SelectAll(query)
        if rets == None:rets = []
        ent_cust_rate_true_count = 0
        ent_cust_rate_false_count = 0
        old_cust_rate_true_count =0
        old_cust_rate_false_count = 0
        for any_group,ent_cust_rate,check_ent_cust_rate,old_cust_rate,check_old_cust_rate in rets:
            #print any_group,ent_cust_rate,check_ent_cust_rate,old_cust_rate,check_old_cust_rate
            if check_ent_cust_rate==None:check_ent_cust_rate=0
            if check_old_cust_rate==None:check_old_cust_rate=0
            if float(ent_cust_rate) == float(check_ent_cust_rate) or round(float(check_ent_cust_rate)-float(ent_cust_rate),3)==0.001 :
                ent_cust_rate_true_count+=1
            else:
                ent_cust_rate_false_count+=1
                
            if float(old_cust_rate)==float(check_old_cust_rate) or round(float(check_old_cust_rate) - float(old_cust_rate),3)==0.001:
                old_cust_rate_true_count+=1
            else:
                old_cust_rate_false_count+=1
        
        if old_cust_rate_false_count==0:
            logging.info(u'Table:%s  验证老顾客占比ByGroup(%s) .... OK'%(tab,old_cust_rate_true_count))
        else:
            logging.error('Table:%s  验证老顾客占比ByGroup(%s:%s) .... Faild'%(tab,old_cust_rate_true_count,old_cust_rate_false_count))
            
        if ent_cust_rate_false_count==0:
            logging.info(u'Table:%s  验证入店率ByGroup(%s) .... OK'%(tab,ent_cust_rate_true_count))
        else:
            logging.error('Table:%s  验证入店率ByGroup(%s:%s) .... Faild'%(tab,ent_cust_rate_true_count,ent_cust_rate_false_count))
            
        
    
    def check_hour_stats_by_group(self,tab='hour_stats_by_group',group=None,groupType=4):
        u'''验证 %s '''%tab
        
        customer_count = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group( role=0, distinct=False, group=group, groupType=groupType)
        
        flow_count = self.myZhimindDatas.get_visit_cnt_by_group(group=group, groupType=groupType, distinct=False)
        
        walkby_count = self.myZhimindDatas.get_walkby_cnt_from_mac_walkby_stats_by_group(group=group, distinct=False,groupType=groupType)
        
        customer_count_check = self.myZhimindDatas.get_count_from_hour_stats_by_group(group= group, groupType=groupType, roleType=1)
        
        flow_count_check = self.myZhimindDatas.get_count_from_hour_stats_by_group(group= group, groupType=groupType, roleType=2)

        walkby_count_check =self.myZhimindDatas.get_count_from_hour_stats_by_group(group= group, groupType=groupType, roleType=3)
        
        if self.__check_two_dict_group_key__(customer_count, customer_count_check):
            logging.info(u'Table:%s  验证顾客人次ByGroup(%s) .... OK'%(tab,sum(customer_count.values())))
        else:
            logging.error('Table:%s  验证顾客人次ByGroup(%s:%s) .... Faild'%(tab,sum(customer_count.values()),sum(customer_count_check.values())))
        
        if self.__check_two_dict_group_key__(flow_count, flow_count_check):
            logging.info(u'Table:%s  验证客流人次ByGroup(%s) .... OK'%(tab,sum(flow_count.values())))
        else:
            logging.error('Table:%s  验证客流人次ByGroup(%s:%s) .... Faild'%(tab,sum(flow_count.values()),sum(flow_count_check.values())))
         
         
        
        if self.__check_two_dict_group_key__(walkby_count, walkby_count_check):
            logging.info(u'Table:%s  验证路人次ByGroup(%s) .... OK'%(tab,sum(walkby_count.values())))
        else:
            logging.error('Table:%s  验证路人次ByGroup(%s:%s) .... Faild'%(tab,sum(walkby_count.values()),sum(walkby_count_check.values())))
        
        
    def check_avg_day_stats_by_group(self,tab='avg_day_stats_by_group',group=None,groupType=4,day=None,roleType=1):
        u'''验证 %s'''%tab
        
        u'''1:入店量；2:客流量;3:路人量;13:新顾客人数;14:新客流人数;15:重复顾客人数;16;重复客流人数'''
        
        customer_count = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group( role=0, distinct=False, group=group, groupType=groupType)
        
        flow_count = self.myZhimindDatas.get_visit_cnt_by_group(group=group, groupType=groupType, distinct=False)
        
        walkby_count = self.myZhimindDatas.get_walkby_cnt_from_mac_walkby_stats_by_group(group=group, distinct=False,groupType=groupType)
        
        new_customer_dist_count = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(role=3, distinct=True, group=group, groupType=groupType)
        
        repeat_customer_dist_count = self.myZhimindDatas.get_customer_cnt_from_mac_customer_stats_by_group(role=10, distinct=True, group=group, groupType=groupType)
        
        
        customer_count_check = self.myZhimindDatas.get_count_from_avg_day_stats_by_group(group=group, roleType=1)
        flow_count_check = self.myZhimindDatas.get_count_from_avg_day_stats_by_group(group=group, roleType=2)
        walkby_count_check = self.myZhimindDatas.get_count_from_avg_day_stats_by_group(group=group, roleType=3)
        new_customer_dist_count_check = self.myZhimindDatas.get_count_from_avg_day_stats_by_group(group=group, roleType=13)
        #new_flow_dist_count_check = self.myZhimindDatas.get_count_from_avg_day_stats_by_group(group=group, roleType=14)
        
        repeat_customer_dist_count_check = self.myZhimindDatas.get_count_from_avg_day_stats_by_group(group=group, roleType=15)
        #repeat_flow_dist_count_check = self.myZhimindDatas.get_count_from_avg_day_stats_by_group(group=group, roleType=16)
        
        if self.__check_two_dict_group_key__(customer_count, customer_count_check):
            logging.info(u'Table:%s  验证顾客人次ByGroup(%s) .... OK'%(tab,sum(customer_count.values())))
        else:
            logging.error('Table:%s  验证顾客人次ByGroup(%s:%s) .... Faild'%(tab,sum(customer_count.values()),sum(customer_count_check.values())))
        
        if self.__check_two_dict_group_key__(flow_count, flow_count_check):
            logging.info(u'Table:%s  验证客流人次ByGroup(%s) .... OK'%(tab,sum(flow_count.values())))
        else:
            logging.error('Table:%s  验证客流人次ByGroup(%s:%s) .... Faild'%(tab,sum(flow_count.values()),sum(flow_count_check.values())))
         
         
        
        if self.__check_two_dict_group_key__(walkby_count, walkby_count_check):
            logging.info(u'Table:%s  验证路人次ByGroup(%s) .... OK'%(tab,sum(walkby_count.values())))
        else:
            logging.error('Table:%s  验证路人次ByGroup(%s:%s) .... Faild'%(tab,sum(walkby_count.values()),sum(walkby_count_check.values())))
        
        
        if self.__check_two_dict_group_key__(new_customer_dist_count, new_customer_dist_count_check):
            logging.info(u'Table:%s  验证新顾客人数ByGroup(%s) .... OK'%(tab,sum(new_customer_dist_count.values())))
        else:
            logging.error('Table:%s  验证新顾客人数ByGroup(%s:%s) .... Faild'%(tab,sum(new_customer_dist_count.values()),sum(new_customer_dist_count_check.values())))
        
        
        if self.__check_two_dict_group_key__(repeat_customer_dist_count, repeat_customer_dist_count_check):
            logging.info(u'Table:%s  验证重复顾客人数ByGroup(%s) .... OK'%(tab,sum(repeat_customer_dist_count.values())))
        else:
            logging.error('Table:%s  验证重复顾客人数ByGroup(%s:%s) .... Faild'%(tab,sum(repeat_customer_dist_count.values()),sum(repeat_customer_dist_count_check.values())))
        
        
        
        
    def check_self_avg_day_stats_by_group(self,tab='avg_day_stats_by_group',group=None,day=None):
        u'''
            %s 自测; max(total_value) == sum(value)
            
            放弃   value 目前系统中计算的是平均值 = total_value/total_weeks
            
        '''%tab
        query = 'select any_group,dayofweek(day) as weekday,type,max(cast(total_value as SIGNED)) as total_value,sum(cast(value as SIGNED)) as sum_value from avg_day_stats_by_group'
        if group!=None:
            query +=' where any_group=%s'%group
        if day!=None and re.search('where',query):
            query+=' and day<="%s"'%day
        elif day!=None:
            query+=' where day<="%s"'%day
            
            
        query+=' group by any_group,weekday,type'
        logging.debug(query)
        rets = self.myZhimindDatas.myZhimind.SelectAll(query)
        if rets==None:rets=[]
        true_count = 0
        false_count = 0
        for group,weekdaynum,ctype,total_value,sum_value in rets:
            
            if int(total_value) == int(sum_value):
                true_count +=1
            else:
                print group,weekdaynum,ctype,total_value,sum_value
                false_count +=1
        if false_count ==0:
            logging.info(u'Table:%s  自测max(total_value) == sum(value) (%s) .... OK'%(tab,true_count))
        else:
            logging.error('Table:%s  自测max(total_value) == sum(value)(%s:%s) .... Faild'%(tab,true_count,false_count))
        
        
        
        
        
    def check_same_target_by_group_in_rank_stats(self,tab='rank_stats',timeType='day',group=None,groupType=4):            
        u'''验证 %s 指标 ： 到访频次(visit_freq),   不计算
                老顾客到访频次(old_cust_visit_freq) 不计算
                '''%tab
        
        visit_freq = self.myZhimindDatas.get_visit_freq_by_group(group=group, groupType=groupType)
        
        #visit_freq = self.myZhimindDatas.get_customer_total_visit_freq_from_mac_customer_stats_by_group(group= group, groupType=groupType, role=0)
        
        visit_freq_check = self.myZhimindDatas.get_one_target_from_rank_stats_by_group(timeType=timeType, group=group, groupType=groupType,  target='visit_freq')
        
        #old_cust_visit_freq_check = self.myZhimindDatas.get_one_target_from_rank_stats_by_group(timeType=timeType, group=group, groupType=groupType,  target='old_cust_visit_freq')
        print visit_freq
        print visit_freq_check
        if self.__check_two_dict_group_key__(visit_freq, visit_freq_check):
            logging.info(u'Table:%s  验证到访频次ByGroup(%s) .... OK'%(tab,sum(visit_freq.values())))
        else:
            logging.error('Table:%s  验证到访频次ByGroup(%s:%s) .... Faild'%(tab,sum(visit_freq.values()),sum(visit_freq_check.values())))
        
#         if self.__check_two_dict_group_key__(old_cust_visit_freq, old_cust_visit_freq_check):
#             logging.info(u'Table:%s  验证老顾客到访频次ByGroup(%s) .... OK'%(tab,sum(old_cust_visit_freq.values())))
#         else:
#             logging.error('Table:%s  验证老顾客到访频次ByGroup(%s:%s) .... Faild'%(tab,sum(old_cust_visit_freq.values()),sum(old_cust_visit_freq_check.values())))
#         
#         
        
    def check_flow_mutation(self,tab='rank_stats',timeType='day',group=None,groupType =4):
        u'''
            验证数据是否突变;相对于前一天是否有大于N倍的增长;
        '''
        day = self.day
        yesterday = (datetime.date(int(day[:4]),int(day[5:7]),int(day[8:10])) - datetime.timedelta(1)).strftime('%Y-%m-%d')
        yest_visit_cnt = self.myZhimindDatas.get_one_target_from_rank_stats_by_group(timeType=timeType, group=group, groupType=groupType, st=yesterday,et = yesterday, target='visit_cnt')
        
        visit_cnt = self.myZhimindDatas.get_one_target_from_rank_stats_by_group(timeType=timeType, group=group, groupType=groupType,st=day,et=day,  target='visit_cnt')
        for group ,value in visit_cnt.items():
            if group in yest_visit_cnt.keys():
                yest_value = yest_visit_cnt[group]
            else:
                continue
            if value / yest_value >=8:
                logging.error('day %s group %s visit_cnt %s / %s >= 8'%(day,group,value,yest_value))
                
        
        
    def check_company_config(self,tab='company_config'):
        u'''
            监控 company_config 是否已经保存了当日的配置文件
        '''
        day = self.day
        
        today = (datetime.date(int(day[:4]),int(day[5:7]),int(day[8:10])) + datetime.timedelta(1)).strftime('%Y-%m-%d')
        config_text = self.myZhimindDatas.get_company_config( day=today)
        
        if config_text!=None and re.search('<config>.*?</config>',config_text):
            logging.info(u'Table:%s Day:%s .... OK'%(tab,today))
        else:
            logging.error(u'Table:%s Day:%s .... Faild'%(tab,today))
        
        
    def check_customer_day_num(self,tab='rank_stats'):
        pass    
    
        
        
    def check_all(self,timeType='day',groupType=4):
        head = '验证 '
        
        if groupType == 0:
            head+='公司级别'
        elif groupType == 1:
            head+='省份级别'
        elif groupType ==2:
            head+='城市级别'
        elif groupType == 4:
            head+='门店级别'
        else:
            logging.error('group_type Error ; 必须输入(0:公司;1:省份;2:城市;4:门店;)')
            
        if timeType == 'day':
            head+=' 天数据 %s'%self.day
        elif timeType == 'week':
            head+=' 周数据 %s-%s'%(self.st,self.et)
        elif timeType == 'month':
            head+=' 月数据 %s-%s'%(self.st,self.et)
        elif timeType == 'quarter':
            head+=' 季度数据 %s-%s'%(self.st,self.et)
        else:
            logging.error('time_type Error ; 必须输入(day,week,month,quarter)')
   
        
        total = 50
        start_num = (total-2-len(head))/2
        end_num = total-2 - len(head) - start_num
        
        head_msg = '#'*total +'\n'+'#'+' '*start_num+head+' '*end_num+'#'+'\n'+'#'*total

        logging.info(head_msg)
        
        if timeType == 'day':
            
            self.check_first_day_by_history(groupType=groupType)    
            self.check_delta_day_by_first_day(groupType=groupType)
        if timeType=='day' and groupType==4:
            self.check_company_config()
            #self.check_customer_flow_with_hive_data(groupType=groupType)
            self.check_hour_stats_by_group(groupType=groupType)
            self.check_avg_day_stats_by_group(groupType=groupType)
            if groupType !=4:
                self.check_region_mac_customer_stats(groupType=groupType)
        
        self.check_customer_cnt_in_customer_type_stats_by_group(timeType=timeType,groupType=groupType)
        #self.check_customer_cnt_in_rank_stats(timeType=timeType,groupType=groupType)
        self.check_deep_jump_customer_cnt_in_customer_type_stats(timeType=timeType)
        self.check_active_customer_equal_old_customer(timeType=timeType,groupType=groupType)
        if timeType == 'day':
            self.check_avg_visit_cycle_in_customer_type_stats(timeType= timeType,groupType=groupType)
        self.check_same_target_by_group_in_customer_type_stats(timeType= timeType,groupType=groupType)
        
         
        self.check_walkby_cnt_in_rank_stats(timeType= timeType,groupType=groupType)
#         self.check_distinct_visit_cnt_in_rank_stats(timeType= timeType,groupType=groupType)
#           
        self.check_same_target_in_rank_stats(timeType=timeType,groupType= groupType)
        self.check_self_target_in_rank_stats( timeType=timeType, groupType=groupType)   
        #self.check_same_target_by_group_in_rank_stats( timeType=timeType, groupType=groupType)
    def main(self,day=None,timeType='day',groupType=4):
        if day==None:
            day = (datetime.date.today()- datetime.timedelta(1)).strftime('%Y-%m-%d')
        
        if timeType == 'day':
            st = day
            et = day
        elif timeType == 'week':
            st,et = myTimeMethod.get_st_et_by_timeType(day, 'week')
            
        elif timeType == 'month':
            st,et = myTimeMethod.get_st_et_by_timeType(day, 'month')
        elif timeType == 'quarter':
            st,et = myTimeMethod.get_st_et_by_timeType(day, 'quarter')
        
        self.st = st
        self.et = et
        self.day = st
        self.myZhimindDatas = ZhimindDatas(st=self.st,et=self.et)
        self.day_query = self.myZhimindDatas.__day_query__(st, et)
        self.check_all(timeType=timeType,groupType=groupType)
            
myZhimindDataCheck = ZhimindDataCheck()     
if __name__ == '__main__':
    import argparse,re,datetime,time
    parser = argparse.ArgumentParser(description='args')
    parser.add_argument('--day',metavar=u"day",default=None)
    parser.add_argument('--time_type',metavar="day week month",default='day')
    parser.add_argument('--group_type',metavar="0,1,2,4",type=int,default=4)
    parser.add_argument('--log_level',metavar="day week month",default='info')
    args = parser.parse_args()
    day = args.day
    #st = et = '2014-02-02'
    timeType = args.time_type
    log_level = args.log_level
    groupType = args.group_type
    #log_level = 'debug'
    if log_level == 'debug':
        level = logging.DEBUG
    elif log_level == 'warn':
        level = logging.WARN
    elif log_level == 'error':
        level = logging.ERROR
    else:
        level = logging.INFO
        
    logging.basicConfig(level=level,format='%(message)s')
    logging.info('check day : %s'%day)
    myZhimindDataCheck.main(day=day,timeType = timeType,groupType=groupType)
    #myZhimindDataCheck.check_customer_flow_with_hive_data(groupType=groupType)
    